
/// <reference path="./modules/define/ConfigDefine.ts" />
/// <reference path="./module/ModuleMgr.ts" />
/// <reference path="./Define.ts" />

const startTime = Date.now()
console.log("apeng core versionCode:" + apeng.versionCode)

/**启动入口 主逻辑运行处*/
namespace apeng {
    /**版本sdk号，可到框架源码处查看更新日志 */
    export var versionCode: number

    /**模块引用脚本，方便其他模块引用 */
    export let _language: LanguageModule = null!
    export let _config: ConfigModule = null!
    export let _server: ServerModule = null!

    /**
     * 初始化主框架
     * 
     */
    export function initCore() {
        moduleMgr.instance()
        _language = moduleMgr.get(EModuleType.language)
        _config = moduleMgr.get(EModuleType.config)
        _server = moduleMgr.get(EModuleType.server)

        moduleMgr.run(() => {
            console.log("apeng core complete duration:" + (Date.now() - startTime))
        }, ELanguageType)
    }


    let defaultType: ELanguageType = CDefaultLanguageType
    /**获取当前语言类型 */
    export function getLanguageType(): ELanguageType {
        let value = localStorage.getItem("language")

        if (value === null || value === "null" || value === undefined || value === "")
            return defaultType
        let type = Number(value)
        if (isNaN(type))
            return defaultType

        if (ELanguageType[type])
            return type
        return defaultType
    }

    /**设置当前的语言id */
    export function setLanguageType(type: ELanguageType) {
        localStorage.setItem("language", type + "")
    }

}

